#!/usr/bin/env python
# -*- coding:utf8 -*-

"""
@version: 
@author: lh
@license: Apache Licence 
@contact: liuhuan0672@gmail.com
@site: 
@software: PyCharm
@file: 0007.py
@time: 2016/1/20 14:54

第 0007 题：有个目录，里面是你自己写过的程序，统计一下你写过多少行代码。包括空行和注释，但是要分别列出来。
"""
import os


def code_lines(target_file):
    # returned values
    total_lines = 0
    empty_lines = 0
    comment_lines = 0

    file_obj = open(target_file, 'r', encoding='utf-8')
    for line in file_obj:
        word_list = line.split()
        if word_list == []:
            empty_lines += 1
        elif word_list[0] == '#':
            comment_lines += 1
        total_lines += 1
    file_obj.close()
    return total_lines, empty_lines, comment_lines


if __name__ == '__main__':
    s = os.listdir('./')
    for f in s:
        if f[-3:] == '.py':
            t_lines, e_lines, c_lines = code_lines(f)
            print('File %s has total %d lines,include %d empty lines '
                  'and %d comment lines.' % (f, t_lines, e_lines, c_lines))
